//
//  UIBarButtonItem+Extension.swift
//  01.XinLangWB
//
//  Created by 肖玉东 on 16/4/12.
//  Copyright © 2016年 苏小样. All rights reserved.
//

import UIKit
extension UIBarButtonItem{
    convenience init(imageName: String? = nil,title: String? = nil, target: AnyObject?, action: Selector) {
        self.init()
        //设置导航栏上的自定义按钮
        let btn = UIButton()
        //添加点击事件
        btn.addTarget(target, action: action, forControlEvents:.TouchUpInside)
        if let img = imageName {
            //解决真机上图片文字离得太近的问题
            btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -5, bottom: 0, right: 5)
            //设置图片
            btn.setImage(UIImage(named: img), forState: .Normal)
            btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
        }
        //设置字体
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.grayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.sizeToFit()
        customView = btn

    }
}